<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="物流公司编码" prop="name">
        <el-input class="w500" v-model="form.logistics_company_code"></el-input>
      </el-form-item>
      <el-form-item label="物流公司名称" prop="description">
        <el-input class="w500" v-model="form.logistics_company_name"></el-input>
      </el-form-item>
      <el-form-item label="运单号" prop="description">
        <el-input class="w500" v-model="form.waybill_number"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit('form')">提交</el-button>
        <el-button @click="goBack">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import notify from '@/tools/notify'

  export default {
    data: function () {
      return {
        form: {
          id: '',
          logistics_company_code: '',
          logistics_company_name: '',
          waybill_number: ''
        },
        rules: {
          logistics_company_name: [
            {required: true, message: '物流公司名称', trigger: 'blur'}
          ],
          waybill_number: [
            {required: true, message: '运单号', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      onSubmit (formName) {
        const self = this
        self.$refs[formName].validate((valid) => {
          self.form.id = self.$route.params.id
          if (valid) {
            this.$store.dispatch('mallorder/shipmentsGoods', this.form).then(res => {
              notify.success(res.msg)
              this.$router.push('/integral/order')
            })
          }
        })
      },
      goBack () {
        this.$router.go(-1)
      }
    }
  }
</script>
